const http = require('http')
const path = require('path')
const fs = require('fs')
const mime = require('mime-types')

const server = http.createServer((req, res) => {
    // const filePath = path.resolve('./01.html')
    // const filePath = path.resolve('./book.json')
    const filePath = path.resolve('./02-test.js')
    fs.readFile(filePath, 'utf8', (err, data) => {
        if (!err) {
            res.writeHead(200, {
                'content-type': mime.lookup(filePath)
            })
            res.write(data)
            res.end()
        }
    })
})

server.listen(8080, () => {
    console.log('server listen on port 8080')
})